//时间格式转换为时间戳
function js_strto_time(time) {
    var new_str = time.replace(/:/g, '-');
    new_str = new_str.replace(/ /g, '-');
    new_str = new_str.replace(/\//g, '-');
    var arr = new_str.split("-");
    var datum = new Date(Date.UTC(arr[0], arr[1] - 1, arr[2], arr[3] - 8, arr[4], arr[5]));
    return strtotime = datum.getTime() / 1000;
}
//时间戳数据转换为时间格式
function js_date_time(unixtime) {
    var timestr = new Date(parseInt(unixtime)*1000);
    var year= timestr.getFullYear(); 
    var month= timestr.getMonth()+1; 
    var date= timestr.getDate(); 
    var hour= timestr.getHours(); 
    var minute= timestr.getMinutes(); 
    var second= timestr.getSeconds(); 
    var datetime = year+"/"+month+"/"+date+" "+hour+":"+minute+":"+second; 
    return datetime;
}
//获取url参数
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)
        return unescape(r[2]);
    return null;
}
function generateParameter() {
    var obj = policyObj;
    obj.PolicyID = $(".policy_id").val();
    obj.MAppType = $(".MAppType").val();
    obj.MAppID = $(".MAppID").val();
    obj.MAppName = $(".MAppName").val();
    obj.M_StartTime = js_strto_time($(".M_StartTime").val());
//    obj.M_StartTime = js_strto_time(obj.M_StartTime) + "";
    obj.M_EndTime = js_strto_time($(".M_EndTime").val());
//    obj.M_EndTime = js_strto_time(obj.M_EndTime) + "";
    obj.M_GroupNo = $(".M_GroupNo").val();
    obj.M_Direction = $(".M_Direction").val();
    obj.MFlowAdd = $(".MFlowAdd").val();
    obj.M_CutLength = $(".M_CutLength").val();
    return obj;
}
//添加数据
function save() {
    var form = $(".main-container .form-horizontal").validate();
    if (!form.form()) {
        return;
    }
    if (MSrcIPSegment.length < 1 || MDstIPSegment.length < 1 || MSrcPortSegment.length < 1 || MDstPortSegment.length < 1 || MDataMatch.length < 1) {
        alert("源和目的IP/端口以及特征字请至少各填写一组!")
    } else {
        var comment = $(".policy_desc").val();
        var obj = generateParameter();
        var parameter = {
            PolicyID: obj.PolicyID,
            MSrcIPSegments: {MSrcIPSegment: MSrcIPSegment}, //MSrcIPSegment,
            MDstIPSegments: {MDstIPSegment: MDstIPSegment}, //MDstIPSegment,
            MSrcPortSegments: {MSrcPortSegment: MSrcPortSegment}, //MSrcPortSegment,
            MDstPortSegments: {MDstPortSegment: MDstPortSegment}, //MDstPortSegment,            
            MAppType: obj.MAppType,
            MAppID: obj.MAppID,
            MAppName: obj.MAppName,
            MDataMatchs: {MDataMatch: MDataMatch}, //MDataMatch,
            M_StartTime: obj.M_StartTime,
            M_EndTime: obj.M_EndTime,
            M_GroupNo: obj.M_GroupNo,
            M_Direction: obj.M_Direction,
            MFlowAdd: obj.MFlowAdd,
            M_CutLength: obj.M_CutLength,
            MessageSerialNo: 0
        }
//        var policy = $.extend(parameter,obj)
        var policy = JSON.stringify(parameter);
//        console.log(policy)
//        return;
        $.ajax({
            type: "POST",
            async: false,
            url: "../../action/policy/create.do",
            data: {comment: comment, policy: policy, type: type, instance: DepotName},
            dataType: "json",
            success: function(data) {
                if (data.result == "true") {
                    alert("添加成功！");
                    previous();
                } else {
                    alert("添加失败!")
                }
            }
        });
    }
}

//返回上一级
function previous() {
    window.location = "../policyList.html?type=" + type + "&id=" + DepotID + "&name=" + base64.encode(DepotName) + "";
}
var policyObj = {
    "PolicyID": Math.floor(new Date().getTime() / 1000) + "",
    "MessageSerialNo": "0"
};

var base64 = new Base64();
var type = getQueryString("type");
var DepotID = getQueryString("DepotID");
var DepotName = getQueryString("DepotName");
DepotName = base64.decode(DepotName);
var id = getQueryString("id");
//源IP地址段
var MSrcIPSegment = [];
//目的IP地址段
var MDstIPSegment = [];
//源端口
var MSrcPortSegment = [];
//目的端口
var MDstPortSegment = [];
//特征字
var MDataMatch = [];
$(function() {
//    console.log("type:" + type + "\tDepotID:" + DepotID + "\tDepotName:" + DepotName + "\tid:" + id)
    $(".header").text(DepotName + "  策略管理");
    //时间插件
    var start = {
        elem: '#M_StartTime',
        format: 'YYYY/MM/DD hh:mm:ss',
        istime: true,
        istoday: false,
        festival: true,
        choose: function(datas) {
            end.min = datas; //开始日选好后，重置结束日的最小日期
            end.start = datas //将结束日的初始值设定为开始日
        }
    };
    var end = {
        elem: '#M_EndTime',
        format: 'YYYY/MM/DD hh:mm:ss',
        istime: true,
        istoday: false,
        festival: true,
        choose: function(datas) {
            start.max = datas; //结束日选好后，重置开始日的最大日期
        }
    };
    laydate(start);
    laydate(end);
    
//    setInterval(function() {
//        parent.$("#page-content").attr("height", $("html").height());
//    }, 500);
});
function showBox() {
    $("#myModal").modal('show');
}
function closeBox() {
    $("#myModal").modal('hide')
    $("#myModal").remove();
}

function addSrcIPBox() {
    var cont = '';
    cont += "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
    cont += "            <div class='modal-dialog'>";
    cont += "                <div class='modal-content'>";
    cont += "                    <div class='modal-header'>";
    cont += "                        <button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span></button>";
    cont += "                        <h4 class='modal-title' id='myModalLabel'>添加源IP地址段</h4>";
    cont += "                    </div>";
    cont += "                    <div class='modal-body'>";
    cont += "                        <form class='form-horizontal'>";
    cont += "                            <div class=' row-fluid'>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='IPType'>IP地址类型：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <select id='IPType' class='IPType'><option>IPv4</option><option>IPv6</option></select>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='IPv4Address'>IP地址：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='IPv4Address' name='IPv4Address' class='IPv4Address ip' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='MSrcIPPrefixLen'>IP地址前缀长度：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='MSrcIPPrefixLen' name='MSrcIPPrefixLen' class='MSrcIPPrefixLen number' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                            </div>";
    cont += "                        </form>";
    cont += "                    </div>";
    cont += "                    <div class='modal-footer'>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-default' onclick='closeBox()'>取消</a>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-primary' onclick='addSrcIP()'>确定</a>";
    cont += "                    </div>";
    cont += "                </div>";
    cont += "            </div>";
    cont += "        </div>";
    $("body").append(cont);
    showBox();
}
function addSrcIP() {
    var form = $("#myModal .form-horizontal").validate();
    if (!form.form()) {
        return;
    }
    var MSrcIPPrefixLen = $("#MSrcIPPrefixLen").val();
    var IPType = $("#IPType").val();
    var IPv4Address = $("#IPv4Address").val();
    var MSrcIPAddr = {
        IPType: IPType,
        IPv4Address: IPv4Address
    };
    var obj = {
        MSrcIPAddr: MSrcIPAddr,
        MSrcIPPrefixLen: MSrcIPPrefixLen
    }
    MSrcIPSegment.push(obj);
    showSrc();
    closeBox();
}
function delSrc(num) {
    MSrcIPSegment.splice(num, 1);
    showSrc();
}
function showSrc() {
    var obj = $(".MSrcIPSegmentNum tbody");
    var cont = "";
    var number = 0;
    for (var i in MSrcIPSegment) {
        cont += "<tr>";
        cont += "<td>" + MSrcIPSegment[i].MSrcIPAddr.IPType + "</td>";
        cont += "<td>" + MSrcIPSegment[i].MSrcIPAddr.IPv4Address + "</td>";
        cont += "<td>" + MSrcIPSegment[i].MSrcIPPrefixLen + "</td>";
        cont += "<td><a href='javascript:delSrc(" + number + ")'>&nbsp;删&nbsp;除&nbsp;</a></td>";
        cont += "</tr>";
        number++;
    }
    obj.html("");
    obj.append(cont);
}

function addDestIPBox() {
    var cont = '';
    cont += "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
    cont += "            <div class='modal-dialog'>";
    cont += "                <div class='modal-content'>";
    cont += "                    <div class='modal-header'>";
    cont += "                        <button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span></button>";
    cont += "                        <h4 class='modal-title' id='myModalLabel'>添加目的IP地址段</h4>";
    cont += "                    </div>";
    cont += "                    <div class='modal-body'>";
    cont += "                        <form class='form-horizontal'>";
    cont += "                            <div class=' row-fluid'>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='IPType'>IP地址类型：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <select id='IPType' class='IPType'><option>IPv4</option><option>IPv6</option></select>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='IPv4Address'>IP地址：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='IPv4Address' name='IPv4Address' class='IPv4Address ip' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='MDstIPPrefixLen'>IP地址前缀长度：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='MDstIPPrefixLen' name='MDstIPPrefixLen' class='MDstIPPrefixLen number' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                            </div>";
    cont += "                        </form>";
    cont += "                    </div>";
    cont += "                    <div class='modal-footer'>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-default' onclick='closeBox()'>取消</a>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-primary' onclick='addDestIP()'>确定</a>";
    cont += "                    </div>";
    cont += "                </div>";
    cont += "            </div>";
    cont += "        </div>";
    $("body").append(cont);
    showBox();
}
function addDestIP() {
    var form = $("#myModal .form-horizontal").validate();
    if (!form.form()) {
        return;
    }
    var MDstIPPrefixLen = $("#MDstIPPrefixLen").val();
    var IPType = $("#IPType").val();
    var IPv4Address = $("#IPv4Address").val();
    var MDstIPAddr = {
        IPType: IPType,
        IPv4Address: IPv4Address
    };
    var obj = {
        MDstIPAddr: MDstIPAddr,
        MDstIPPrefixLen: MDstIPPrefixLen

    }
    MDstIPSegment.push(obj);
    showDest();
    closeBox();
}
function delDest(num) {
    MDstIPSegment.splice(num, 1);
    showDest();
}
function showDest() {
    var obj = $(".MDstIPSegmentNum tbody");
    var cont = "";
    var number = 0;
    for (var i in MDstIPSegment) {
        cont += "<tr>";
        cont += "<td>" + MDstIPSegment[i].MDstIPAddr.IPType + "</td>";
        cont += "<td>" + MDstIPSegment[i].MDstIPAddr.IPv4Address + "</td>";
        cont += "<td>" + MDstIPSegment[i].MDstIPPrefixLen + "</td>";
        cont += "<td><a href='javascript:delDest(" + number + ")'>&nbsp;删&nbsp;除&nbsp;</a></td>";
        cont += "</tr>";
        number++;
    }
    obj.html("");
    obj.append(cont);
}

function addMatchBox() {
    var cont = '';
    cont += "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
    cont += "            <div class='modal-dialog'>";
    cont += "                <div class='modal-content'>";
    cont += "                    <div class='modal-header'>";
    cont += "                        <button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span></button>";
    cont += "                        <h4 class='modal-title' id='myModalLabel'>添加特征字</h4>";
    cont += "                    </div>";
    cont += "                    <div class='modal-body'>";
    cont += "                        <form class='form-horizontal'>";
    cont += "                            <div class=' row-fluid'>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='MDataMatchOffset'>偏移大小：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='MDataMatchOffset' name='MDataMatchOffset' class='MDataMatchOffset number' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='MDataMatchContent'>需要匹配的字符串：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='MDataMatchContent' name='MDataMatchContent' class='MDataMatchContent' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                            </div>";
    cont += "                        </form>";
    cont += "                    </div>";
    cont += "                    <div class='modal-footer'>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-default' onclick='closeBox()'>取消</a>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-primary' onclick='addMatch()'>确定</a>";
    cont += "                    </div>";
    cont += "                </div>";
    cont += "            </div>";
    cont += "        </div>";
    $("body").append(cont);
    showBox();
}
function addMatch() {
    var form = $("#myModal .form-horizontal").validate();
    if (!form.form()) {
        return;
    }
    var MDataMatchOffset = $("#MDataMatchOffset").val();
    var MDataMatchContent = $("#MDataMatchContent").val();
    var obj = {
        MDataMatchOffset: MDataMatchOffset,
        MDataMatchContent: MDataMatchContent
    }
    MDataMatch.push(obj);
    showMatch();
    closeBox();
}
function delMatch(num) {
    MDataMatch.splice(num, 1);
    showMatch();
}
function showMatch() {
    var obj = $(".MDataMatchNum tbody");
    var cont = "";
    var number = 0;
    for (var i in MDataMatch) {
        cont += "<tr>";
        cont += "<td>" + MDataMatch[i].MDataMatchOffset + "</td>";
        cont += "<td>" + MDataMatch[i].MDataMatchContent + "</td>";
        cont += "<td><a href='javascript:delMatch(" + number + ")'>&nbsp;删&nbsp;除&nbsp;</a></td>";
        cont += "</tr>";
        number++;
    }
    obj.html("");
    obj.append(cont);
}

function addSrcPortBox() {
    var cont = '';
    cont += "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
    cont += "            <div class='modal-dialog'>";
    cont += "                <div class='modal-content'>";
    cont += "                    <div class='modal-header'>";
    cont += "                        <button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span></button>";
    cont += "                        <h4 class='modal-title' id='myModalLabel'>添加源端口</h4>";
    cont += "                    </div>";
    cont += "                    <div class='modal-body'>";
    cont += "                        <form class='form-horizontal'>";
    cont += "                            <div class=' row-fluid'>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='MSrcPortStart'>起始端口：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='MSrcPortStart' name='MSrcPortStart' class='MSrcPortStart number' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='MSrcPortEnd'>结束端口：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='MSrcPortEnd' name='MSrcPortEnd' class='MSrcPortEnd number' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                            </div>";
    cont += "                        </form>";
    cont += "                    </div>";
    cont += "                    <div class='modal-footer'>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-default' onclick='closeBox()'>取消</a>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-primary' onclick='addSrcPort()'>确定</a>";
    cont += "                    </div>";
    cont += "                </div>";
    cont += "            </div>";
    cont += "        </div>";
    $("body").append(cont);
    showBox();
}
function addSrcPort() {
    var form = $("#myModal .form-horizontal").validate();
    if (!form.form()) {
        return;
    }
    var MSrcPortStart = $("#MSrcPortStart").val();
    var MSrcPortEnd = $("#MSrcPortEnd").val();
    var obj = {
        MSrcPortStart: MSrcPortStart,
        MSrcPortEnd: MSrcPortEnd
    }
    MSrcPortSegment.push(obj);
    showSrcPort();
    closeBox();
}
function delSrcPort(num) {
    MSrcPortSegment.splice(num, 1);
    showSrcPort();
}
function showSrcPort() {
    var obj = $(".MSrcPortSegmentNum tbody");
    var cont = "";
    var number = 0;
    for (var i in MSrcPortSegment) {
        cont += "<tr>";
        cont += "<td>" + MSrcPortSegment[i].MSrcPortStart + "</td>";
        cont += "<td>" + MSrcPortSegment[i].MSrcPortEnd + "</td>";
        cont += "<td><a href='javascript:delSrcPort(" + number + ")'>&nbsp;删&nbsp;除&nbsp;</a></td>";
        cont += "</tr>";
        number++;
    }
    obj.html("");
    obj.append(cont);
}

function addDestPortBox() {
    var cont = '';
    cont += "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>";
    cont += "            <div class='modal-dialog'>";
    cont += "                <div class='modal-content'>";
    cont += "                    <div class='modal-header'>";
    cont += "                        <button type='button' class='close' data-dismiss='modal'><span aria-hidden='true'>&times;</span></button>";
    cont += "                        <h4 class='modal-title' id='myModalLabel'>添加目的端口</h4>";
    cont += "                    </div>";
    cont += "                    <div class='modal-body'>";
    cont += "                        <form class='form-horizontal'>";
    cont += "                            <div class=' row-fluid'>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='MDstPortStart'>起始端口：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='MDstPortStart' name='MDstPortStart' class='MDstPortStart number' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                                <div class='control-group'>";
    cont += "                                    <label class='control-label' for='MDstPortEnd'>结束端口：</label>";
    cont += "                                    <div class='controls'>";
    cont += "                                        <input type='text' id='MDstPortEnd' name='MDstPortEnd' class='MDstPortEnd number' required/>";
    cont += "                                    </div>";
    cont += "                                </div>";
    cont += "                            </div>";
    cont += "                        </form>";
    cont += "                    </div>";
    cont += "                    <div class='modal-footer'>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-default' onclick='closeBox()'>取消</a>";
    cont += "                        <a href='javascript:void(0)' class='btn btn-primary' onclick='addDestPort()'>确定</a>";
    cont += "                    </div>";
    cont += "                </div>";
    cont += "            </div>";
    cont += "        </div>";
    $("body").append(cont);
    showBox();
}
function addDestPort() {
    var form = $("#myModal .form-horizontal").validate();
    if (!form.form()) {
        return;
    }
    var MDstPortStart = $("#MDstPortStart").val();
    var MDstPortEnd = $("#MDstPortEnd").val();
    var obj = {
        MDstPortStart: MDstPortStart,
        MDstPortEnd: MDstPortEnd
    }
    MDstPortSegment.push(obj);
    showDestPort();
    closeBox();
}
function delDestPort(num) {
    MDstPortSegment.splice(num, 1);
    showDestPort();
}
function showDestPort() {
    var obj = $(".MDstPortSegmentNum tbody");
    var cont = "";
    var number = 0;
    for (var i in MDstPortSegment) {
        cont += "<tr>";
        cont += "<td>" + MDstPortSegment[i].MDstPortStart + "</td>";
        cont += "<td>" + MDstPortSegment[i].MDstPortEnd + "</td>";
        cont += "<td><a href='javascript:delDestPort(" + number + ")'>&nbsp;删&nbsp;除&nbsp;</a></td>";
        cont += "</tr>";
        number++;
    }
    obj.html("");
    obj.append(cont);
}

function showData(souData) {
    var messageType = souData.MessageType;
    var messageNo = souData.MessageNo;
    var instanceName = souData.Instance;
    var comment = souData.Comment;
    policyObj = souData.Content;

    MDataMatch = policyObj.MDataMatchs.MDataMatch;
    MSrcIPSegment = policyObj.MSrcIPSegments.MSrcIPSegment;
    MSrcPortSegment = policyObj.MSrcPortSegments.MSrcPortSegment;
    MDstIPSegment = policyObj.MDstIPSegments.MDstIPSegment;
    MDstPortSegment = policyObj.MDstPortSegments.MDstPortSegment;

    $(".policy_desc").val(comment);
    $(".policy_id").val(policyObj.PolicyID);
    $(".MAppType").val(policyObj.MAppType + "");
    $(".MAppID").val(policyObj.MAppID + "");
    $(".MAppName").val(policyObj.MAppName + "");
    $('#M_StartTime').val(js_date_time(policyObj.M_StartTime * 1));
    $('#M_EndTime').val(js_date_time(policyObj.M_EndTime * 1));
    $(".M_GroupNo").val(policyObj.M_GroupNo + "");
    $(".M_Direction").val(policyObj.M_Direction + "");
    $(".MFlowAdd").val(policyObj.MFlowAdd + "");
    $(".M_CutLength").val(policyObj.M_CutLength + "");

    showSrcPort();
    showSrc();
    showDest();
    showDestPort();
    showMatch();
}

function edit() {
    var form = $(".main-container .form-horizontal").validate();
    if (!form.form()) {
        return;
    }
    if (MSrcIPSegment.length < 1 || MDstIPSegment.length < 1 || MSrcPortSegment.length < 1 || MDstPortSegment.length < 1 || MDataMatch.length < 1) {
        alert("源和目的IP/端口以及特征字请至少各填写一组!")
    } else {
        var comment = $(".policy_desc").val();
        var obj = generateParameter();
        var parameter = {
            PolicyID: obj.PolicyID,
            MSrcIPSegments: {MSrcIPSegment: MSrcIPSegment}, //MSrcIPSegment,
            MDstIPSegments: {MDstIPSegment: MDstIPSegment}, //MDstIPSegment,
            MSrcPortSegments: {MSrcPortSegment: MSrcPortSegment}, //MSrcPortSegment,
            MDstPortSegments: {MDstPortSegment: MDstPortSegment}, //MDstPortSegment,            
            MAppType: obj.MAppType,
            MAppID: obj.MAppID,
            MAppName: obj.MAppName,
            MDataMatchs: {MDataMatch: MDataMatch}, //MDataMatch,
            M_StartTime: obj.M_StartTime,
            M_EndTime: obj.M_EndTime,
            M_GroupNo: obj.M_GroupNo,
            M_Direction: obj.M_Direction,
            MFlowAdd: obj.MFlowAdd,
            M_CutLength: obj.M_CutLength,
            MessageSerialNo: 0
        }
//        var policy = $.extend(parameter,obj)
        var policy = JSON.stringify(parameter);
//        console.log(policy)
//        return;
        $.ajax({
            type: "POST",
            async: false,
            url: "../../action/policy/update.do",
            data: {messageNo: id, comment: comment, policy: policy, type: type, instance: DepotName},
            dataType: "json",
            success: function(data) {
                if (data.result == "true") {
                    alert("编辑成功！");
                    previous();
                } else {
                    alert("编辑失败!")
                }
            }
        });
    }
}
/*
 * 查看旧版本的策略内容
 */
function show_oldPolicy(array, number) {
    var souData = array[number];
    $(".header").text("当前策略在" + souData.CreateTime + "创建,ID为" + souData.MessageNo + ",版本号为" + souData.MessageSerialNo + ",属于" + souData.Instance + "策略库");

    showData(souData);
}

/*
 *获取所有版本的策略内容 
 */
function getAllPolicy() {
    $.ajax({
        type: "GET",
        async: false,
        url: "../../action/policy/history_policy_info.do",
        data: {type: type, instance: getQueryString("DepotName"), messageNo: id},
        dataType: "json",
        success: function(data) {
            policyArray = data;
            policyAmount = data.length
        }
    });
}